﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KTFrameworkCus;

public partial class Controls_Survey : System.Web.UI.UserControl
{
    double Count;
    static double TotalCount = 0;
    int i = 0;
    KTFrameworkCusEntities _oTHER = new KTFrameworkCusEntities();

    protected void Page_Load(object sender, EventArgs e)
    {
        Data_Bind();
    }
    public void Data_Bind()
    {
        var questionID = _oTHER.Votes.Where(v => v.Visible == true).FirstOrDefault().VoteID;
        var answers = _oTHER.Votes.Where(v => v.ParentID == questionID);
        TotalCount = answers.Sum(a => a.Score).Value;
        GridViewItem.DataSource = answers;
        GridViewItem.DataBind();

        string strLabel = GetLanguage("Tổng lượt bình chọn: ","Total votes: ");
        lblCount.Text = strLabel + TotalCount.ToString();
    }
    protected string GetPercentage(int RatingLevelID)
    {

        var answer = _oTHER.Votes.Where(v => v.VoteID == RatingLevelID).FirstOrDefault();

        double Percent = 0;
        if (TotalCount > 0)
        {
            Percent = ((double)answer.Score.Value / TotalCount) * 100;
        }
        string result = Math.Round(Percent, 1).ToString() + "%"; //Percent.ToString() + " %";

        Count = TotalCount;
        return result;
    }
    protected string GetAutoIDSpan()
    {
        i++;
        string IdSpan = "Span" + i.ToString();
        return IdSpan;
    }
    public string GetLanguage(string strVN, string strEN)
    {
        var currentLanguage = Session["language"] == null ? "vi-VN" : Session["language"].ToString();

        switch (currentLanguage)
        {
            case "vi-VN":
                return strVN;
            case "en-US":
                return strEN;
            default:
                return strVN;
        }
    }
}